/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.admin;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.ResourceBundle;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import model.*;

/**
 *
 * @author Administrator
 */
@ManagedBean(name = "cvmb")
@SessionScoped
public class CVManagedBean {
    @EJB
    private ApplicantFacade applicantFacade;
    @EJB
    private VacancyFacade vacancyFacade;
    @EJB
    private CvFacade cvFacade;
    private String ApplicantID;
    private String VacancyID;
    private String message = new String();

    public void setApplicantFacade(ApplicantFacade applicantFacade) {
        this.applicantFacade = applicantFacade;
    }

    public ApplicantFacade getApplicantFacade() {
        return applicantFacade;
    }

    public String getMessage() {
        return message;
    }
    public String getApplicantID() {
        return ApplicantID;
    }

    public void setApplicantID(String ApplicantID) {
        this.ApplicantID = ApplicantID;
    }

    public String getVacancyID() {
        return VacancyID;
    }

    public void setVacancyID(String VacancyID) {
        this.VacancyID = VacancyID;
    }
    
    
    
    private Cv cv = new Cv();

    public Cv getCv() {
        return cv;
    }

    public void setCv(Cv cv) {
        this.cv = cv;
    }

    public VacancyFacade getVacancyFacade() {
        return vacancyFacade;
    }

    public void setVacancyFacade(VacancyFacade vacancyFacade) {
        this.vacancyFacade = vacancyFacade;
    }

    public CvFacade getCvFacade() {
        return cvFacade;
    }

    public void setCvFacade(CvFacade cvFacade) {
        this.cvFacade = cvFacade;
    }

 
public void vacancyList(){
     this.cvFacade.findAll();
}

   
    public CVManagedBean() {
    }
    public String addcv(){
        String CvID = generateID();
       this.cv.setCvid(CvID);
        this.cv.setApplicantID(this.applicantFacade.find(this.ApplicantID));
        this.cv.setVacancyID(this.vacancyFacade.find(this.VacancyID));
        this.cvFacade.create(this.cv);
        return "List";
    }
    public String editcv(){
        this.cv.setApplicantID(this.applicantFacade.find(this.ApplicantID));
        this.cv.setVacancyID(this.vacancyFacade.find(this.VacancyID));
        this.cvFacade.edit(this.cv);
        return "List";
    }
    public String deletecv(Cv cv){
        String page = "";
        try {
            this.cvFacade.remove(cv);
            page = "List";
        } catch (Exception e) {
            this.message ="Delete not found";
        }
        
        return page;
    }
    public List<Cv> cvList(){
        return this.cvFacade.findAll();
    }
    public List<Vacancy> vacList(){
        return this.vacancyFacade.findAll();
    }
    public List<Applicant> appList(){
        return this.applicantFacade.findAll();
    }
    
    public String cvEdit(Cv cv){
        this.cv = cv;
        return "Edit";
    }
    public String cvView(Cv cv){
        this.cv = cv;
        return "View";
    }
    
    private String generateID() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        
        return "CV" + sdf.format(new Date());
    }
   
}
